package com.ruoyi.service.impl;

import com.ruoyi.common.core.text.Convert;
import com.ruoyi.entity.po.TActivitySwitch;
import com.ruoyi.mapper.TActivitySwitchMapper;
import com.ruoyi.service.ITActivitySwitchService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

/**
 * 活动状态Service业务层处理
 *
 * @author ruoyi
 * @date 2024-12-07
 */
@Service
public class ActivitySwitchServiceImpl implements ITActivitySwitchService {

    private final TActivitySwitchMapper tActivitySwitchMapper;

    public ActivitySwitchServiceImpl(TActivitySwitchMapper tActivitySwitchMapper) {
        this.tActivitySwitchMapper = tActivitySwitchMapper;
    }

    /**
     * 查询活动状态
     *
     * @param id 活动状态主键
     * @return 活动状态
     */
    @Override
    public TActivitySwitch selectTActivitySwitchById(Long id) {
        return tActivitySwitchMapper.selectTActivitySwitchById(id);
    }

    /**
     * 查询活动状态列表
     *
     * @param tActivitySwitch 活动状态
     * @return 活动状态
     */
    @Override
    public List<TActivitySwitch> selectTActivitySwitchList(TActivitySwitch tActivitySwitch) {
        return tActivitySwitchMapper.selectTActivitySwitchList(tActivitySwitch);
    }

    /**
     * 新增活动状态
     *
     * @param tActivitySwitch 活动状态
     * @return 结果
     */
    @Override
    public int insertTActivitySwitch(TActivitySwitch tActivitySwitch) {
        return tActivitySwitchMapper.insertTActivitySwitch(tActivitySwitch);
    }

    /**
     * 修改活动状态
     *
     * @param tActivitySwitch 活动状态
     * @return 结果
     */
    @Override
    public int updateTActivitySwitch(TActivitySwitch tActivitySwitch) {
        return tActivitySwitchMapper.updateTActivitySwitch(tActivitySwitch);
    }

    /**
     * 批量删除活动状态
     *
     * @param ids 需要删除的活动状态主键
     * @return 结果
     */
    @Override
    public int deleteTActivitySwitchByIds(String ids) {
        return tActivitySwitchMapper.deleteTActivitySwitchByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除活动状态信息
     *
     * @param id 活动状态主键
     * @return 结果
     */
    @Override
    public int deleteTActivitySwitchById(Long id) {
        return tActivitySwitchMapper.deleteTActivitySwitchById(id);
    }

    @Override
    public boolean getStatusByCode(String activityCode) {
        return Optional.ofNullable(tActivitySwitchMapper.getStatusByCode(activityCode)).orElse(false);
    }

    @Override
    public int enableOrDisable(Integer activityId, Boolean targetStatus) {
        return tActivitySwitchMapper.enableOrDisable(activityId,targetStatus);
    }
}
